/*
 * addon_ddlutil.cpp
 *
 *  Created on: 2010-1-7
 *      Author: gavinkwoe
 */

#include "addon_features.h"

#if (__ADDON_TARGET__ == __TARGET_SYMBIAN)

#include "addon_std.h"
#include "addon_mem.h"
#include "addon_objbase.h"
#include "addon_dllutil.h"
#include "addon_file.h"
#include "addon_observer.h"


#if defined(__ADDON_USE_CX_FILE__)
#include "cx_file.h"
//#ifdef PLATFORM_SYMBIAN
//#include "FileSearch.h"
//#endif

//#include <f32file.h>
#else	// #if defined(__ADDON_USE_CX_FILE__)
#include <e32const.h>
#include <e32std.h>
#include <libc\stdio.h>
#include <f32file.h>
#endif	// #if defined(__ADDON_USE_CX_FILE__)

/*************************************************************************
* GUID
*************************************************************************/

ADDON_DEFINED_GUID( IAddonFile, 1, "62EE9F13-74F3-442f-A485-5E87DECD9462" )
ADDON_DEFINED_GUID( IAddonFileSearch, 1, "0AAAF53C-139D-48a1-A55F-A288C16AC3D4" )

/*************************************************************************
* CLASS
*************************************************************************/
//#ifdef PLATFORM_SYMBIAN
//class CSearchObserver : public MFileSearchObserver
//{
//public:
//	
//	CSearchObserver();
//	~CSearchObserver();
//	
//	void SetObserver( ADDON_REF(IObject) obsrv );
//
//	void FindOneFile( const unsigned short * afilename,int alen);
//	void SearchFinished( void );
//	void SearchCancelled( void );
//	void SearchCurrentStatus( int aNbDir, int aNbFiles );
//	
//private:
//	
//	ADDON_REF(IObject) _obsrv;
//};
//
//
//struct __struct_addon_FileSearch_data
//{
//	unsigned long		ref_cnt;	// reference count
//	unsigned long		has_start;
//	CFileSearcher *		searcher;
//	CSearchObserver *	obsrv;
//};
//#endif

/*************************************************************************
* STRUCTURE
*************************************************************************/

struct __struct_addon_File_data;
typedef struct __struct_addon_File_data		addon_File_data_t;
typedef struct __struct_addon_File_data *	addon_File_data_ptr_t;

struct __struct_addon_FileSearch_data;
typedef struct __struct_addon_FileSearch_data	addon_FileSearch_data_t;
typedef struct __struct_addon_FileSearch_data *	addon_FileSearch_data_ptr_t;

/*************************************************************************
* DEFINITION
*************************************************************************/

struct __struct_addon_File_data
{
	unsigned long		ref_cnt;	// reference count

#if defined(__ADDON_USE_CX_FILE__)
	CXFILE				file_hdle;
#else	// #if defined(__ADDON_USE_CX_FILE__)
	unsigned long		file_size;
	FILE *				file_hdle;
#endif	// #if defined(__ADDON_USE_CX_FILE__)
};


/*************************************************************************
* LOCAL FUNCTIONS
*************************************************************************/

unsigned long	__CFile_Construct( ADDON_REF(IObject) thiz, void * usr_data );
unsigned long	__CFile_Destruct( ADDON_REF(IObject) thiz );
unsigned long	__CFile_AddRef( ADDON_REF(IObject) thiz );
unsigned long	__CFile_Release( ADDON_REF(IObject) thiz );

unsigned long	__CFile_HasOpen( ADDON_REF(IObject) thiz, unsigned long * flag );
unsigned long	__CFile_Open( ADDON_REF(IObject) thiz, unsigned short * fname );
unsigned long	__CFile_Create( ADDON_REF(IObject) thiz, unsigned short * fname );
unsigned long	__CFile_Close( ADDON_REF(IObject) thiz );
unsigned long	__CFile_GetSize( ADDON_REF(IObject) thiz, unsigned long * size );
unsigned long	__CFile_GetOffset( ADDON_REF(IObject) thiz, unsigned long * offset );
unsigned long	__CFile_Seek( ADDON_REF(IObject) thiz, unsigned long offset );
unsigned long	__CFile_Read( ADDON_REF(IObject) thiz, void * buff, unsigned long size, unsigned long * read_size );
unsigned long	__CFile_Write( ADDON_REF(IObject) thiz, void * buff, unsigned long size, unsigned long * write_size );


// const void * const __coclass_vtbl[] =
// {
// 	// IObject
// 	(void *)__CFile_Construct,
// 		(void *)__CFile_Destruct,
// 		(void *)__CFile_AddRef,
// 		(void *)__CFile_Release,
// 		
// 		// IAddonDLL
// 		(void *)__CFile_HasOpen,
// 		(void *)__CFile_Open,
// 		(void *)__CFile_Create,
// 		(void *)__CFile_Close,
// 		(void *)__CFile_GetSize,
// 		(void *)__CFile_GetOffset,
// 		(void *)__CFile_Seek,
// 		(void *)__CFile_Read,
// 		(void *)__CFile_Write
// };
// 
// const addon_coclass_desc_t __coclass_desc =
// {
// 	(unsigned char *)__coclass_vtbl,
// 		(unsigned long)sizeof( addon_File_data_t )
// 	};
//
//#ifdef PLATFORM_SYMBIAN
//unsigned long	__CFileSearch_Construct( ADDON_REF(IObject) thiz, void * usr_data );
//unsigned long	__CFileSearch_Destruct( ADDON_REF(IObject) thiz );
//unsigned long	__CFileSearch_AddRef( ADDON_REF(IObject) thiz );
//unsigned long	__CFileSearch_Release( ADDON_REF(IObject) thiz );
//
//unsigned long	__CFileSearch_HasStart( ADDON_REF(IObject) thiz, unsigned long * flag );
//unsigned long	__CFileSearch_Start( ADDON_REF(IObject) thiz, ADDON_REF(IObject) obsrv );
//unsigned long	__CFileSearch_Stop( ADDON_REF(IObject) thiz );


// const void * const __coclass_vtbl[] =
// {
// 	// IObject
// 	(void *)__CFileSearch_Construct,
// 		(void *)__CFileSearch_Destruct,
// 		(void *)__CFileSearch_AddRef,
// 		(void *)__CFileSearch_Release,
// 		
// 		// IAddonFileSearch
// 		(void *)__CFileSearch_HasStart,
// 		(void *)__CFileSearch_Start,
// 		(void *)__CFileSearch_Stop
// };
// 
// const addon_coclass_desc_t __coclass_desc =
// {
// 	(unsigned char *)__coclass_vtbl,
// 		(unsigned long)sizeof( addon_FileSearch_data_t )
// };

/*************************************************************************
* IMPLEMENTATION
*************************************************************************/

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
//CSearchObserver::CSearchObserver() : _obsrv( NULL )
//{
//	
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//CSearchObserver::~CSearchObserver()
//{
//	OBJECT_SAFE_RELEASE( _obsrv );
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//void
//CSearchObserver::SetObserver( ADDON_REF(IObject) obsrv )
//{
//	OBJECT_ASSIGN( _obsrv, obsrv );
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//void
//CSearchObserver::FindOneFile( const unsigned short * afilename ,int alen)
//{
//	//unsigned short * file_name = (unsigned short *)aFile.Ptr();
//	unsigned short * file_name = (unsigned short *)afilename;
//	IAddonObserver_OnNotify( _obsrv, ADDON_NTF_FILESEARCH_FOUND, (void **)&file_name );
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//void
//CSearchObserver::SearchFinished( void )
//{
//	IAddonObserver_OnNotify( _obsrv, ADDON_NTF_FILESEARCH_FINISH, NULL );
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//void
//CSearchObserver::SearchCancelled( void )
//{
//	IAddonObserver_OnNotify( _obsrv, ADDON_NTF_FILESEARCH_CANCEL, NULL );	
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//void
//CSearchObserver::SearchCurrentStatus( TInt aNbDir, TInt aNbFiles )
//{
//	ADDON_UNUSED( aNbDir );
//	ADDON_UNUSED( aNbFiles );
//}
//
//#endif


/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_Construct( ADDON_REF(IObject) thiz, void * usr_data )
{
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );

	ADDON_UNUSED( usr_data );
	
	if ( NULL == obj_data )
		return ADDON_FAILED;

	obj_data->ref_cnt	= 1;

#if defined(__ADDON_USE_CX_FILE__)
	obj_data->file_hdle.fileHandle_ = NULL;
#else	// #if defined(__ADDON_USE_CX_FILE__)
	obj_data->file_size	= 0;
	obj_data->file_hdle	= NULL;
#endif	// #if defined(__ADDON_USE_CX_FILE__)
	
	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_Destruct( ADDON_REF(IObject) thiz )
{
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );

	if ( NULL == obj_data )
		return ADDON_FAILED;
	
	__CFile_Close( thiz );	
	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_AddRef( ADDON_REF(IObject) thiz )
{
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );

	if ( NULL == obj_data )
		return ADDON_FAILED;
	
	obj_data->ref_cnt++;
	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_Release( ADDON_REF(IObject) thiz )
{
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );

	if ( NULL == obj_data )
		return ADDON_FAILED;
	
	obj_data->ref_cnt -= 1;

	if ( 0 == obj_data->ref_cnt )
	{
		addon_obj_delete( (void *)thiz );
	}
	
	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_HasOpen( ADDON_REF(IObject) thiz, unsigned long * flag )
{
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );
	
	if ( NULL == obj_data || NULL == flag )
		return ADDON_FAILED;

#if defined(__ADDON_USE_CX_FILE__)
	*flag = ( QFALSE == cx_file_isValid(obj_data->file_hdle) ? ADDON_FALSE : ADDON_TRUE );
#else	// #if defined(__ADDON_USE_CX_FILE__)
	*flag = ( NULL == obj_data->file_hdle ? ADDON_FALSE : ADDON_TRUE );
#endif	// #if defined(__ADDON_USE_CX_FILE__)
	
	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_Open( ADDON_REF(IObject) thiz, unsigned short * fname )
{
#ifndef __ADDON_USE_CX_FILE__
	long old_pos = 0;
	long end_pos = 0;
#endif	// #ifndef __ADDON_USE_CX_FILE__
	
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );
	
	if ( NULL == obj_data || NULL == fname )
		return ADDON_FAILED;

	__CFile_Close( thiz );

#if defined(__ADDON_USE_CX_FILE__)
	obj_data->file_hdle = cx_file_open( (CONST QTCHAR*)fname, modeReadWrite );
	if ( QFALSE == cx_file_isValid(obj_data->file_hdle) )
		return ADDON_FAILED;
#else	// #if defined(__ADDON_USE_CX_FILE__)
	obj_data->file_hdle = wfopen( (LPCWSTR)fname, (LPCWSTR)L"r" );
	if ( NULL == obj_data->file_hdle )
		return ADDON_FAILED;

	old_pos = ftell( obj_data->file_hdle );

	fseek( obj_data->file_hdle, 0, SEEK_END );
	end_pos = ftell( obj_data->file_hdle );
	fseek( obj_data->file_hdle, old_pos, SEEK_SET );

	obj_data->file_size = (unsigned long)end_pos;
#endif	// #if defined(__ADDON_USE_CX_FILE__)
	
	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_Create( ADDON_REF(IObject) thiz, unsigned short * fname )
{
#ifndef __ADDON_USE_CX_FILE__
	long old_pos = 0;
	long end_pos = 0;
#endif	// #ifndef __ADDON_USE_CX_FILE__
	
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );
	
	if ( NULL == obj_data || NULL == fname )
		return ADDON_FAILED;

	__CFile_Close( thiz );

#if defined(__ADDON_USE_CX_FILE__)
	obj_data->file_hdle = cx_file_open( (CONST QTCHAR*)fname, modeReadWrite|modeCreate );
	if ( QFALSE == cx_file_isValid(obj_data->file_hdle) )
		return ADDON_FAILED;
#else	// #if defined(__ADDON_USE_CX_FILE__)
	obj_data->file_hdle = wfopen( (LPCWSTR)fname, (LPCWSTR)L"w" );
	if ( NULL == obj_data->file_hdle )
		return ADDON_FAILED;

	old_pos = ftell( obj_data->file_hdle );

	fseek( obj_data->file_hdle, 0, SEEK_END );
	end_pos = ftell( obj_data->file_hdle );
	fseek( obj_data->file_hdle, old_pos, SEEK_SET );

	obj_data->file_size = (unsigned long)end_pos;
#endif	// #if defined(__ADDON_USE_CX_FILE__)
	
	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_Close( ADDON_REF(IObject) thiz )
{
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );
	
	if ( NULL == obj_data )
		return ADDON_FAILED;

#if defined(__ADDON_USE_CX_FILE__)
	if ( QFALSE != cx_file_isValid( obj_data->file_hdle ) )
	{
		cx_file_close( &(obj_data->file_hdle) );
		obj_data->file_hdle.fileHandle_ = NULL;	
	}
#else	// #if defined(__ADDON_USE_CX_FILE__)
	if ( NULL != obj_data->file_hdle )
	{
		fclose( obj_data->file_hdle );
		obj_data->file_hdle = NULL;
	}

	obj_data->file_size = 0;
#endif	// #if defined(__ADDON_USE_CX_FILE__)

	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_GetSize( ADDON_REF(IObject) thiz, unsigned long * size )
{
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );
	
	if ( NULL == obj_data || NULL == size )
		return ADDON_FAILED;

#if defined(__ADDON_USE_CX_FILE__)
	*size = cx_file_size( obj_data->file_hdle );
#else	// #if defined(__ADDON_USE_CX_FILE__)	
	if ( NULL == obj_data->file_hdle )
	{
		*size = 0;
		return ADDON_FAILED;
	}

	*size = obj_data->file_size;
#endif	// #if defined(__ADDON_USE_CX_FILE__)
	
	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_GetOffset( ADDON_REF(IObject) thiz, unsigned long * offset )
{
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );
	
	if ( NULL == obj_data || NULL == offset )
		return ADDON_FAILED;
	
#if defined(__ADDON_USE_CX_FILE__)
	*offset = cx_file_tell( obj_data->file_hdle );
#else	// #if defined(__ADDON_USE_CX_FILE__)	
	if ( NULL == obj_data->file_hdle )
	{
		*offset = 0;
		return ADDON_FAILED;
	}

	*offset = (unsigned long)ftell( obj_data->file_hdle );
#endif	// #if defined(__ADDON_USE_CX_FILE__)

	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_Seek( ADDON_REF(IObject) thiz, unsigned long offset )
{
#if defined(__ADDON_USE_CX_FILE__)
	QLONG	ret_val;
#else	// #if defined(__ADDON_USE_CX_FILE__)
	size_t	ret_val;
#endif	// #if defined(__ADDON_USE_CX_FILE__)
	
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );
	
	if ( NULL == obj_data )
		return ADDON_FAILED;
	
#if defined(__ADDON_USE_CX_FILE__)
	ret_val = cx_file_seek( obj_data->file_hdle, offset, CX_FILE_BEGIN );
	if ( QFALSE == ret_val )
		return ADDON_FAILED;
#else	// #if defined(__ADDON_USE_CX_FILE__)
	if ( NULL == obj_data->file_hdle )
		return ADDON_FAILED;
	
	ret_val = fseek( obj_data->file_hdle, (long)offset, SEEK_SET );
	if ( ret_val < 0 )
		return ADDON_FAILED;
#endif	// #if defined(__ADDON_USE_CX_FILE__)

	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_Read( ADDON_REF(IObject) thiz, void * buff, unsigned long size, unsigned long * read_size )
{
#if defined(__ADDON_USE_CX_FILE__)
	QINT	ret_val;
#else	// #if defined(__ADDON_USE_CX_FILE__)
	size_t	ret_val;
#endif	// #if defined(__ADDON_USE_CX_FILE__)
	
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );
	
	if ( NULL == obj_data || NULL == buff || 0 == size || NULL == read_size )
		return ADDON_FAILED;
	
#if defined(__ADDON_USE_CX_FILE__)
	ret_val = cx_file_read( obj_data->file_hdle, (QVOID *)buff, (QUINT)size );
	if ( 0 == ret_val )
		return ADDON_FAILED;

	*read_size = ret_val;
#else	// #if defined(__ADDON_USE_CX_FILE__)
	if ( NULL == obj_data->file_hdle )
		return ADDON_FAILED;
	
	ret_val = fread( buff, size, 1, obj_data->file_hdle );
	if ( 0 == ret_val )
		return ADDON_FAILED;
	
	*read_size = ret_val;
#endif	// #if defined(__ADDON_USE_CX_FILE__)
	
	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
unsigned long __CFile_Write( ADDON_REF(IObject) thiz, void * buff, unsigned long size, unsigned long * write_size )
{
#if defined(__ADDON_USE_CX_FILE__)
	QINT	ret_val;
#else	// #if defined(__ADDON_USE_CX_FILE__)
	size_t	ret_val;
#endif	// #if defined(__ADDON_USE_CX_FILE__)
	
	addon_File_data_ptr_t obj_data = (addon_File_data_ptr_t)ADDON_GET_DATA( thiz );
	
	if ( NULL == obj_data || NULL == buff || 0 == size || NULL == write_size )
		return ADDON_FAILED;
	
#if defined(__ADDON_USE_CX_FILE__)
	ret_val = cx_file_write( obj_data->file_hdle, (QVOID *)buff, (QUINT)size );
	if ( 0 == ret_val )
		return ADDON_FAILED;
	
	*write_size = ret_val;
#else	// #if defined(__ADDON_USE_CX_FILE__)
	if ( NULL == obj_data->file_hdle )
		return ADDON_FAILED;
	
	ret_val = fwrite( buff, size, 1, obj_data->file_hdle );
	if ( 0 == ret_val )
		return ADDON_FAILED;
	
	*write_size = ret_val;
#endif	// #if defined(__ADDON_USE_CX_FILE__)
	
	return ADDON_OK;
}

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
ADDON_EXPORT ADDON_REF(IObject) addon_create_file( void * reserved )
{
	//static const 
	void * __coclass_vtbl[13];// =
	//{
	// IObject
	int i=0;
	__coclass_vtbl[i++] = 	(void *)__CFile_Construct;
	__coclass_vtbl[i++] = 	(void *)__CFile_Destruct;
	__coclass_vtbl[i++] = 	(void *)__CFile_AddRef;
	__coclass_vtbl[i++] = 	(void *)__CFile_Release;
	
	// IAddonDLL
	__coclass_vtbl[i++] = 	(void *)__CFile_HasOpen;
	__coclass_vtbl[i++] = 	(void *)__CFile_Open;
	__coclass_vtbl[i++] = 	(void *)__CFile_Create;
	__coclass_vtbl[i++] = 	(void *)__CFile_Close;
	__coclass_vtbl[i++] = 	(void *)__CFile_GetSize;
	__coclass_vtbl[i++] = 	(void *)__CFile_GetOffset;
	__coclass_vtbl[i++] = 	(void *)__CFile_Seek;
	__coclass_vtbl[i++] = 	(void *)__CFile_Read;
	__coclass_vtbl[i++] = 	(void *)__CFile_Write;
	//};
	
	//static const 
	addon_coclass_desc_t __coclass_desc;

	__coclass_desc.vtbl_size	= (unsigned long)sizeof(__coclass_vtbl);
	__coclass_desc.vtbl_funcs	= (unsigned char *)__coclass_vtbl;
	__coclass_desc.priv_size	= (unsigned long)sizeof(addon_File_data_t);

	return ( ADDON_REF(IObject) )addon_obj_new( (addon_coclass_desc_ptr_t)&__coclass_desc, reserved );
}

//#ifdef PLATFORM_SYMBIAN
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//unsigned long __CFileSearch_Construct( ADDON_REF(IObject) thiz, void * usr_data )
//{
//	addon_FileSearch_data_ptr_t obj_data = (addon_FileSearch_data_ptr_t)ADDON_GET_DATA( thiz );
//
//	ADDON_UNUSED( usr_data );
//	
//	if ( NULL == obj_data )
//		return ADDON_FAILED;
//
//	obj_data->ref_cnt	= 1;
//	obj_data->has_start	= 0;
//	obj_data->obsrv		= NULL;
//	obj_data->searcher	= NULL;
//	
//	return ADDON_OK;
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//unsigned long __CFileSearch_Destruct( ADDON_REF(IObject) thiz )
//{
//	addon_FileSearch_data_ptr_t obj_data = (addon_FileSearch_data_ptr_t)ADDON_GET_DATA( thiz );
//
//	if ( NULL == obj_data )
//		return ADDON_FAILED;
//	
//	__CFileSearch_Stop( thiz );
//	
//	delete obj_data->obsrv;
//	delete obj_data->searcher;
//	
//	return ADDON_OK;
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//unsigned long __CFileSearch_AddRef( ADDON_REF(IObject) thiz )
//{
//	addon_FileSearch_data_ptr_t obj_data = (addon_FileSearch_data_ptr_t)ADDON_GET_DATA( thiz );
//
//	if ( NULL == obj_data )
//		return ADDON_FAILED;
//	
//	obj_data->ref_cnt++;
//	return ADDON_OK;
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//unsigned long __CFileSearch_Release( ADDON_REF(IObject) thiz )
//{
//	addon_FileSearch_data_ptr_t obj_data = (addon_FileSearch_data_ptr_t)ADDON_GET_DATA( thiz );
//
//	if ( NULL == obj_data )
//		return ADDON_FAILED;
//	
//	obj_data->ref_cnt -= 1;
//
//	if ( 0 == obj_data->ref_cnt )
//	{
//		addon_obj_delete( (void *)thiz );
//	}
//	
//	return ADDON_OK;
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//unsigned long __CFileSearch_HasStart( ADDON_REF(IObject) thiz, unsigned long * flag )
//{
//	addon_FileSearch_data_ptr_t obj_data = (addon_FileSearch_data_ptr_t)ADDON_GET_DATA( thiz );
//
//	if ( NULL == obj_data || NULL == flag )
//		return ADDON_FAILED;
//	
//	*flag = obj_data->has_start;
//	return ADDON_OK;
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//unsigned long __CFileSearch_Start( ADDON_REF(IObject) thiz, ADDON_REF(IObject) obsrv )
//{
//	//RFs & rfs = CCoeEnv::Static()->FsSession();
//	addon_FileSearch_data_ptr_t	obj_data = (addon_FileSearch_data_ptr_t)ADDON_GET_DATA( thiz );
//
//	if ( NULL == obj_data || NULL == obsrv )
//		return ADDON_FAILED;
//	
//	__CFileSearch_Stop( thiz );
//
//	obj_data->obsrv = new CSearchObserver;
//	if ( NULL == obj_data->obsrv )
//		goto __FAILED;
//
//	obj_data->obsrv->SetObserver( obsrv );
//	
//	obj_data->searcher = CFileSearcher::NewL( obj_data->obsrv );
//	if ( NULL == obj_data->searcher )
//		goto __FAILED;
//
//	obj_data->searcher->SetPriority( CActive::EPriorityStandard );
//	obj_data->searcher->SearchAllDrives( );
//
//	obj_data->has_start = 1;
//	return ADDON_OK;
//	
//__FAILED:
//	if ( NULL != obj_data->searcher )
//	{
//		delete obj_data->searcher;
//		obj_data->searcher = NULL;
//	}
//	if ( NULL != obj_data->obsrv )
//	{
//		obj_data->obsrv->SetObserver( NULL );
//		delete obj_data->obsrv;
//	}
//	return ADDON_FAILED;
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//unsigned long __CFileSearch_Stop( ADDON_REF(IObject) thiz )
//{
//	addon_FileSearch_data_ptr_t	obj_data = (addon_FileSearch_data_ptr_t)ADDON_GET_DATA( thiz );
//
//	if ( NULL == obj_data )
//		return ADDON_FAILED;
//	
//	if ( 0 != obj_data->has_start )
//	{
//	if ( NULL != obj_data->searcher )
//	{
//		obj_data->searcher->CancelSearch( ETrue );
//		obj_data->searcher->ClearSearch();
//		
//		delete obj_data->searcher;
//		obj_data->searcher = NULL;
//	}
//	
//	if ( NULL != obj_data->obsrv )
//	{
//			obj_data->obsrv->SearchCancelled();
//		obj_data->obsrv->SetObserver( NULL );
//			
//		delete obj_data->obsrv;
//			obj_data->obsrv = NULL;
//	}
//	
//		obj_data->has_start = 0;
//	}
//	
//	return ADDON_OK;
//}
//
///*************************************************************************
//* DESCRIPTION
//*	$$__FUNC_DESC__$$
//*************************************************************************/
//ADDON_EXPORT ADDON_REF(IObject) addon_create_filesearch( void * reserved )
//{
//	//static const 
//	void * __coclass_vtbl[] =
//	{
//		// IObject
//		(void *)__CFileSearch_Construct,
//		(void *)__CFileSearch_Destruct,
//		(void *)__CFileSearch_AddRef,
//		(void *)__CFileSearch_Release,
//
//		// IAddonFileSearch
//		(void *)__CFileSearch_HasStart,
//		(void *)__CFileSearch_Start,
//		(void *)__CFileSearch_Stop
//	};
//	
//// 	static const addon_coclass_desc_t __coclass_desc =
//// 	{
//// 		(unsigned char *)__coclass_vtbl,
//// 		(unsigned long)sizeof( addon_FileSearch_data_t )
//// 	};
//	addon_coclass_desc_t __coclass_desc;
//
//	__coclass_desc.vtbl_size	= (unsigned long)sizeof(__coclass_vtbl);
//	__coclass_desc.vtbl_funcs	= (unsigned char *)__coclass_vtbl;
//	__coclass_desc.priv_size	= (unsigned long)sizeof(addon_FileSearch_data_t);
//
//
//	return ( ADDON_REF(IObject) )addon_obj_new( (addon_coclass_desc_ptr_t)&__coclass_desc, reserved );
//
//// 	coclass_desc_t __coclass_desc;
//// 	
//// 	__coclass_desc.vtbl_size	= (unsigned long)sizeof(__coclass_vtbl);
//// 	__coclass_desc.vtbl_funcs	= (unsigned char *)__coclass_vtbl;
//// 	__coclass_desc.priv_size	= (unsigned long)sizeof(CFile_data);
//// 	
//// 	return (C_REF(IObject))c_obj_new( (coclass_desc_ptr_t)&__coclass_desc, reserved );
//
//}
//#endif

#else	// #if (__ADDON_TARGET__ == __TARGET_SYMBIAN)

/*************************************************************************
* DESCRIPTION
*	$$__FUNC_DESC__$$
*************************************************************************/
ADDON_EXPORT ADDON_REF(IObject) addon_create_file( void * reserved )
{
	ADDON_UNUSED( reserved );
	return NULL;
}

ADDON_EXPORT ADDON_REF(IObject) addon_create_filesearch( void * reserved )
{
	ADDON_UNUSED( reserved );
	return NULL;
}

#endif	// #if (__ADDON_TARGET__ == __TARGET_SYMBIAN)
